package main

import (
	"fmt"
	"functional/fib"
	"functional/tree"
)

func main() {
	/*f := fib.Fibonacci()
	for i := 0; i < 10; i++ {
		fmt.Println(f())
	}*/

	// 打印斐波那契数列
	var f1 fib.IntGen = fib.Fibonacci()
	fib.PrintFileContents(f1)

	// 生成树
	var root tree.Node

	root = tree.Node{Value: 3}
	root.Left = &tree.Node{}
	root.Right = &tree.Node{5, nil, nil}
	root.Right.Left = new(tree.Node)
	root.Left.Right = tree.CreateNode(2)
	root.Right.Left.SetValue(4)

	// 遍历树
	root.Traverse()

	// 遍历树 计算节点总数
	nodeCount := 0
	root.TraverseFunc(func(node *tree.Node) {
		nodeCount++
	})
	fmt.Println("Node count:", nodeCount)

	// channel 遍历树找到最大节点
	c := root.TraverseWithChannel()
	maxNodeValue := 0
	for node := range c {
		if node.Value > maxNodeValue {
			maxNodeValue = node.Value
		}
	}
	fmt.Println("Max node value:", maxNodeValue)
}
